package com.abcdefg.webpagechatprojectbymyself.api;

import com.abcdefg.webpagechatprojectbymyself.mapper.MessageMapper;
import com.abcdefg.webpagechatprojectbymyself.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

@RequestMapping("/MessageApi")
@RestController
public class MessageApi {
    @Autowired
    private MessageMapper messageMapper;

    //获取消息
    @GetMapping("/getMessage")
    public Object getMessage(int sessionId){
        List<Message> message =
                messageMapper.getMessageBySessionId(sessionId);
        //这里需要翻转一下，界面最先显示的消息需要时刚发送的
        Collections.reverse(message);
        return message;
    }
}
